#ifndef LIST_H
#define LIST_H

#include <stddef.h>
#include "TElement.h"
#include "SharedPointer.h"
#include "IInformation.h"

template<class TContent>
class List {
private:
	size_t size;
	TElement<TContent>* first;
	TElement<TContent>* last;
	bool isEmpty1;

public:
	List() :
			size(0), isEmpty1(true) {
		first = NULL;
		last = NULL;

	}
	virtual ~List() {
	}
	// note toself: encapsulate tcontent in telement during the inserting
	// in our case content ist shared pointer to iinformation btw
	void instert(size_t size, TContent* content);

	TContent* get(size_t index){
		TElement<TContent>* iti;
		iti = first;
		for (size_t i = 0; i<index; i++){
			iti++;
		}
		return iti->getContent();
	}
	// note to self: encapsulate tcontent in telement
	SharedPointer<IInformation>* append(TContent* content) {
		if (isEmpty1) {
			// forever-alone-element
			SharedPointer<IInformation>* iinf =
					new SharedPointer<IInformation>((IInformation*)content);
			TElement<TContent>* newElement = new TElement<TContent>(content,
					newElement, newElement);
			isEmpty1 = false;
			first = newElement;
			last = newElement;
			return iinf;
		} else {
            // traverse list to check if equal element present or just hash collision
			TElement<TContent>* iti;
			iti = first;
			while (iti != last) {
				//the element is equal
				if (iti->getContent() == content) {
					return new SharedPointer<IInformation>((IInformation*)content);
				}
				iti++;
			}
			// no equal element present ergohash collision so doing a true append
			// new element is the new last and the old last is the new previous
			SharedPointer<IInformation>* iinf =
					new SharedPointer<IInformation>((IInformation*)content);
			TElement<TContent>* newElement = new TElement<TContent>(content,
					newElement, newElement);
			last->setPrev(newElement);
			last = newElement;
			return iinf;

		}

	}

	void deleteList();
	bool isEmpty() {
		return isEmpty1;
	}
};

#endif
